package com.echo.ssm.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import com.echo.ssm.mapper.SonMapper;
import com.echo.ssm.model.Son;
import com.github.pagehelper.PageHelper;

import net.sf.jsqlparser.expression.CaseExpression;

/***
 * 
 * 业务处理层
 * @author tangsixiang
 *
 */
//增加注解 作为服务层的  [组件]
@Service
public class SonService {
	//引用持久层的【组件】
	@Resource
	private  SonMapper sonMapper;
	public int deleteByPrimaryKey(Integer sonId) {

		return sonMapper.deleteByPrimaryKey(sonId);
	}
	
	/**
	 * 固定字段个数保存数据
	 * @param record
	 * @return
	 */
	public int insert(Son record) {
		// Integer.parseInt("abc");
		return sonMapper.insert(record);
	}
	
	/**
	 * 动态字段个数保存数据
	 * @param record
	 * @return
	 */
	
	//如果当前存在事务，则加入该事务；如果当前没有事务，则创建一个新的事务。这是默认值。
	//---默认值  
	@Transactional(noRollbackFor={NumberFormatException.class},isolation=Isolation.SERIALIZABLE)
	public int insertSelective(Son record) throws Exception {
		  
		sonMapper.updateByPrimaryKeySelective(record);
		return   sonMapper.insertSelective(record);
	}
	@Transactional
	public int updateByPrimaryKeySelective(Son record) {
		return sonMapper.updateByPrimaryKeySelective(record);
	}
	public Son selectByPrimaryKey(Integer sonId) {
		return sonMapper.selectByPrimaryKey(sonId);
	}
	public List<Son> selectByPagesList(Integer pageSize,Integer pageNum) {
		 PageHelper.startPage(pageNum, pageSize);
		return sonMapper.selectByPagesList();
	}


	public int updateByPrimaryKey(Son record) {

		return sonMapper.updateByPrimaryKey(record);
	}
/*	public List<Son> selectBySonParam(Son record) {
		return sonMapper.selectByPrimaryKey(sonId);
	}*/

}
